package com.market.service.impl;

import com.market.entity.base.Fruit;
import com.market.entity.dto.OrderDto;
import com.market.pay.base.PricingStrategy;
import com.market.pay.details.BasePricingStrategy;
import com.market.pay.details.FullReductionStrategy;
import com.market.pay.details.StrawberryDiscountStrategy;
import com.market.service.MarKetService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Slf4j
@Service
@RequiredArgsConstructor
public class MarketServiceImpl implements MarKetService {

    // 顾客A: 苹果和草莓（无折扣）
    public BigDecimal calculateCustomerA(double appleKg, double strawberryKg) {

        OrderDto orderDto = new OrderDto();
        orderDto.addItem(Fruit.APPLE, new BigDecimal(appleKg));
        orderDto.addItem(Fruit.STRAWBERRY, new BigDecimal(strawberryKg));
        return new BasePricingStrategy().calculateTotal(orderDto);
    }

    // 顾客B: 苹果、草莓、芒果（无折扣）
    public BigDecimal calculateCustomerB(double appleKg, double strawberryKg, double mangoKg) {
        OrderDto orderDto = new OrderDto();
        orderDto.addItem(Fruit.APPLE, new BigDecimal(appleKg));
        orderDto.addItem(Fruit.STRAWBERRY, new BigDecimal(strawberryKg));
        orderDto.addItem(Fruit.MANGO, new BigDecimal(mangoKg));
        return new BasePricingStrategy().calculateTotal(orderDto);
    }

    // 顾客C: 草莓打8折
    public BigDecimal calculateCustomerC(double appleKg, double strawberryKg, double mangoKg) {
        OrderDto orderDto = new OrderDto();
        orderDto.addItem(Fruit.APPLE, new BigDecimal(appleKg));
        orderDto.addItem(Fruit.STRAWBERRY, new BigDecimal(strawberryKg));
        orderDto.addItem(Fruit.MANGO, new BigDecimal(mangoKg));
        PricingStrategy strategy = new StrawberryDiscountStrategy(new BasePricingStrategy());
        return strategy.calculateTotal(orderDto);
    }

    // 顾客D: 草莓8折 + 满100减10
    public BigDecimal calculateCustomerD(double appleKg, double strawberryKg, double mangoKg) {
        OrderDto orderDto = new OrderDto();
        orderDto.addItem(Fruit.APPLE, new BigDecimal(appleKg));
        orderDto.addItem(Fruit.STRAWBERRY, new BigDecimal(strawberryKg));
        orderDto.addItem(Fruit.MANGO, new BigDecimal(mangoKg));
        PricingStrategy strategy = new FullReductionStrategy(
                new StrawberryDiscountStrategy(new BasePricingStrategy())
        );
        return strategy.calculateTotal(orderDto);
    }
}
